<?php

namespace App\Repositories\Eloquent;

use App\Models\CityWeather;
use App\Repositories\Contracts\WeatherInterface;
use MakeRep\Repository;

class WeatherRepository extends Repository implements WeatherInterface
{

    public $view = 'weather';
    public $fillable = ['id','city_id','date','weather','temperature','img_url'];

    function model()
    {
        return CityWeather::class;
    }

    /**
     * 获取天气
     * @param $param
     * @return mixed
     */
    public function cityWeather($cityCode){

        $cityInterface = resolve('App\Repositories\Contracts\CityInterface');
        $city = $cityInterface->index(['city_code'=>$cityCode]);

        $where = [
            ['date','>=',date('Y-m-d')],
            ['city_id','=',$city['id']]
        ];

        return $this->get($where,'*',[],'date');
    }
}